package com.yyds.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyds.common.MyJSON;
import com.yyds.mapper.VaccineVaccineMapper;
import com.yyds.pojo.VaccineVaccine;
import com.yyds.service.VaccineVaccineService;
import com.yyds.vo.EchartPieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("vaccineVaccineService")
public class VaccineVaccineServiceImpl implements VaccineVaccineService {

    @Autowired
    @Qualifier("vaccineVaccineMapper")
    private VaccineVaccineMapper vaccineVaccineMapper;


    @Override
    public Integer insertVaccineVaccineService(VaccineVaccine vaccine) {
        return vaccineVaccineMapper.insertVaccineVaccineMapper(vaccine);
    }

    @Override
    public Integer deleteVaccineVaccineService(Integer vaccine_id) {
        return vaccineVaccineMapper.deleteVaccineVaccineMapper(vaccine_id);
    }

    @Override
    public Integer deleteAllVaccineVaccineService(String str) {
        //1001-1002-1003-
        String[] strs = str.split("-");
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < strs.length; i++) {
            list.add(Integer.parseInt(strs[i]));
        }
        return vaccineVaccineMapper.deleteAllVaccineVaccineMapper(list);
    }

    @Override
    public Integer updateVaccineVaccineService(VaccineVaccine newVaccine) {
        VaccineVaccine oldVaccine = vaccineVaccineMapper.querySingleVaccineVaccineMapper(newVaccine.getVaccine_id());
        return vaccineVaccineMapper.updateVaccineVaccineMapper(oldVaccine, newVaccine);
    }

    @Override
    public MyJSON<VaccineVaccine> queryVaccineVaccineService(Map<String, Object> map) {
        int page = Integer.parseInt(map.get("page") + "");
        int limit = Integer.parseInt(map.get("limit") + "");
        PageHelper.startPage(page, limit);
        List<VaccineVaccine> vaccines = vaccineVaccineMapper.queryVaccineVaccineMapper(map);
        PageInfo<VaccineVaccine> pageInfo = new PageInfo<>(vaccines);
        MyJSON<VaccineVaccine> myJSON = new MyJSON<>();
        myJSON.setMsg("全部疫苗种类信息");
        myJSON.setCode(0);
        myJSON.setData(pageInfo.getList());
        myJSON.setCount(pageInfo.getTotal());
        return myJSON;
    }

    @Override
    public List<EchartPieVo> queryVaccineVarietyService() {
        return vaccineVaccineMapper.queryVaccineVarietyMapper();
    }

    @Override
    public List<String> queryVaccineNameService() {
        return vaccineVaccineMapper.queryVaccineNameMapper();
    }
}
